Dynomotion

Group: DynoMotion Message: 12312 From: Hardy Family Date: 9/25/2015
Subject: Behavior when no PC attached
Hi Tom,

We have a program on the kflop which basically runs forever, and does not need a PC attached.  The program uses printf() and I just noticed that the machine stopped working after a long run, then started working again when I attached a PC.

Is that a problem with printf()?  For a stand-alone program, should we make sure there are no printfs?

Does the kflop discard console messages at some point, or do they queue up until the buffer is full, and then printf() will block?

Regards,
SJH

Group: DynoMotion Message: 12313 From: Hardy Family Date: 9/25/2015
Subject: Re: Behavior when no PC attached
PS: the connection really seems to go south when this happens: trying to restart the app to connect to the kflop results in all sorts of wierdness; had to power it off and on to get back some sanity.

For this application, I would like to retain the printfs for diagnostics, but we don't want it to break during normal operation without any USB connection (this is a really big customer with a lot of our machines!)  Any suggestions?


On Fri, Sep 25, 2015 at 5:16 PM, Hardy Family <hardy.woodland.cypress@...> wrote:
Hi Tom,

We have a program on the kflop which basically runs forever, and does not need a PC attached.  The program uses printf() and I just noticed that the machine stopped working after a long run, then started working again when I attached a PC.

Is that a problem with printf()?  For a stand-alone program, should we make sure there are no printfs?

Does the kflop discard console messages at some point, or do they queue up until the buffer is full, and then printf() will block?

Regards,
SJH


Group: DynoMotion Message: 12314 From: Tom Kerekes Date: 9/25/2015
Subject: Re: Behavior when no PC attached
Hi SJH,

The Console Message were only intended for diagnostics.  KFLOP has a circular queue for Console Messages for 256 Strings.  When it is full printf messages will block as shown below.  Checking the circular indexes can be used to determine how many strings are in the queue.

HTH
Regards
TK



#define MAX_NSTRINGS 256  // must be binary    
extern volatile int NextAvailIn=0;  // when these are equal the queue is empty
extern volatile int NextAvailOut=0;

 // wait if queue full
 while (((NextAvailIn+1)&(MAX_NSTRINGS-1)) == (NextAvailOut&(MAX_NSTRINGS-1)));

Group: DynoMotion Message: 12315 From: Hardy Family Date: 9/25/2015
Subject: Re: Behavior when no PC attached
Hi Tom,

Thanks for the quick response.  Is there a way to simply discard the console queue if it gets beyond a certain threshold (i.e. no PC is accepting the messages)?  We would like to retain the messages for diagnostic purposes, but obviously they need to be discarded if no PC.

To give up when half the buffer is used, would
if ((NextAvailIn-NextAvailOut & MAX_NSTRINGS-1) > MAX_NSTRINGS/2)
     NextAvailOut=NextAvailIn;
work?

On a related note, I noticed when restarting the PC in this situation, it would get awfully confused.  I'm using the Linux version of KMotionServer, and it seems to have a flaw in that it gets confused when initially opening the USB port if there is outstanding data coming from the kflop.  It obviously needs to be modified to rapidly discard pending data like console messages until it can sync to the data stream. 

Currently, in CKMotionIO::FlushInputBuffer() at the end it waits for 3 chars ESC, 'C', '\r' but that doesn't seem to always work reliably after unusual situations.  Maybe SendAbortOnConnect is not getting set.

Regards,
SJH


On Fri, Sep 25, 2015 at 5:34 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

Hi SJH,

The Console Message were only intended for diagnostics.  KFLOP has a circular queue for Console Messages for 256 Strings.  When it is full printf messages will block as shown below.  Checking the circular indexes can be used to determine how many strings are in the queue.

HTH
Regards
TK



#define MAX_NSTRINGS 256  // must be binary    
extern volatile int NextAvailIn=0;  // when these are equal the queue is empty
extern volatile int NextAvailOut=0;

 // wait if queue full
 while (((NextAvailIn+1)&(MAX_NSTRINGS-1)) == (NextAvailOut&(MAX_NSTRINGS-1)));

Group: DynoMotion Message: 12316 From: Tom Kerekes Date: 9/25/2015
Subject: Re: Behavior when no PC attached
Hi SJH,

Looks reasonable except I think modifying NextAvailIn would be safer as your Thread should only modify the "In" index and the KFLOP Thread should only modify the "Out" index. 

We'll have to look at how things sync with pending data.  I see the same confusion with the Windows code.

Regards
TK